package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseExecutionResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricActivityInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricDetailResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricProcessInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricTaskInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricVariableInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseProcessInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseTaskResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.ExecutionQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricActivityInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricDetailQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricProcessInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricTaskInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricVariableInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.ProcessInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.TaskQueryRequest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.QueryApi")
public class QueryApi {
    private ApiClient apiClient;

    public QueryApi() {
        this(new ApiClient());
    }

    @Autowired
    public QueryApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Query for historic activity instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic task instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     * <p><b>200</b> - Indicates request was successful and the activities are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information
     * @param body The body parameter
     * @return DataResponseHistoricActivityInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricActivityInstanceResponse queryActivityInstances(HistoricActivityInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-activity-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricActivityInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricActivityInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query executions
     * The request body can contain all possible filters that can be used in the List executions URL query. On top of these, it’s possible to provide an array of variables and processInstanceVariables to include in the query, with their format described here.  The general paging and sorting query-parameters can be used for this URL.
     * <p><b>200</b> - Indicates request was successful and the executions are returned.
     * <p><b>404</b> - Indicates a parameter was passed in the wrong format . The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseExecutionResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseExecutionResponse queryExecutions(ExecutionQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/executions").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseExecutionResponse> returnType = new ParameterizedTypeReference<DataResponseExecutionResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic details
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     * <p><b>200</b> - Indicates request was successful and the historic details are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricDetailResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricDetailResponse queryHistoricDetail(HistoricDetailQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-detail").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricDetailResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricDetailResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic process instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on process variables. The variables property is a JSON-array containing objects with the format as described here.
     * <p><b>200</b> - Indicates request was successful and the process instances are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricProcessInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricProcessInstanceResponse queryHistoricProcessInstance(HistoricProcessInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-process-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricProcessInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricProcessInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic task instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic task instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on process variables. The taskVariables and processVariables properties are JSON-arrays containing objects with the format as described here.
     * <p><b>200</b> - Indicates request was successful and the tasks are returned
     * <p><b>404</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricTaskInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricTaskInstanceResponse queryHistoricTaskInstance(HistoricTaskInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-task-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricTaskInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricTaskInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query process instances
     * The request body can contain all possible filters that can be used in the List process instances URL query. On top of these, it’s possible to provide an array of variables to include in the query, with their format described here.  The general paging and sorting query-parameters can be used for this URL.
     * <p><b>200</b> - Indicates request was successful and the process-instances are returned
     * <p><b>400</b> - Indicates a parameter was passed in the wrong format . The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseProcessInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseProcessInstanceResponse queryProcessInstances(ProcessInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/process-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseProcessInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseProcessInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for tasks
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of tasks (except for candidateGroupIn which is only available in this POST task query REST service), but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on task and process variables. The taskVariables and processInstanceVariables are both JSON-arrays containing objects with the format as described here.
     * <p><b>200</b> - Indicates request was successful and the tasks are returned.
     * <p><b>400</b> - Indicates a parameter was passed in the wrong format or that delegationState has an invalid value (other than pending and resolved). The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseTaskResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseTaskResponse queryTasks(TaskQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/tasks").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseTaskResponse> returnType = new ParameterizedTypeReference<DataResponseTaskResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic variable instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on process variables. The variables property is a JSON-array containing objects with the format as described here.
     * <p><b>200</b> - Indicates request was successful and the tasks are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricVariableInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricVariableInstanceResponse queryVariableInstances(HistoricVariableInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-variable-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricVariableInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricVariableInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
